Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add qml.math.grad and qml.math.jacobian for differentiating any interface #6741

Merged
merged 17 commits into from
Dec 31, 2024

Conversation

albi3ro
Copy link
Contributor

@albi3ro albi3ro commented Dec 27, 2024

Context:

We often have to rewrite tests four different ways to test differentiability for each different interface. This is rather time-intensive and annoying. By adding and using a qml.math.grad, we can write one test that applies to all interfaces.

Description of the Change:

Adds a qml.math.grad and qml.math.jacobian with a jax-like interface that can differentiate with respect to any argument inputs.

Benefits:

Possible Drawbacks:

We have several different options for interface, but I decided to do my best to mirror the jax interface.

Related GitHub Issues:

Copy link

codecov bot commented Dec 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.60%. Comparing base (b9df1e1) to head (e0fa72d).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6741   +/-   ##
=======================================
  Coverage   99.60%   99.60%           
=======================================
  Files         475      476    +1     
  Lines       45121    45210   +89     
=======================================
+ Hits        44944    45033   +89     
  Misses        177      177           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@albi3ro albi3ro changed the title add qml.math.grad for differentiating any interface add qml.math.grad and qml.math.jacobian for differentiating any interface Dec 27, 2024
Copy link
Contributor

@PietropaoloFrisoni PietropaoloFrisoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 🥳

pennylane/math/grad.py Outdated Show resolved Hide resolved
pennylane/math/grad.py Outdated Show resolved Hide resolved
pennylane/math/grad.py Show resolved Hide resolved
pennylane/math/grad.py Outdated Show resolved Hide resolved
@PietropaoloFrisoni PietropaoloFrisoni added this to the v0.40 milestone Dec 30, 2024
tests/math/test_grad.py Outdated Show resolved Hide resolved
pennylane/math/grad.py Show resolved Hide resolved
Copy link
Contributor

@PietropaoloFrisoni PietropaoloFrisoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few suggestions to match the doc output on my laptop. Please let me know if it is different on yours 👍

pennylane/_grad.py Outdated Show resolved Hide resolved
pennylane/math/grad.py Outdated Show resolved Hide resolved
pennylane/math/grad.py Outdated Show resolved Hide resolved
pennylane/math/grad.py Outdated Show resolved Hide resolved
pennylane/math/grad.py Outdated Show resolved Hide resolved
pennylane/math/grad.py Outdated Show resolved Hide resolved
pennylane/math/grad.py Outdated Show resolved Hide resolved
pennylane/math/grad.py Outdated Show resolved Hide resolved
Copy link
Contributor

@JerryChen97 JerryChen97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all good on my side! Just several minor suggestions on error msg. Thanks a lot!

pennylane/math/grad.py Outdated Show resolved Hide resolved
pennylane/_grad.py Outdated Show resolved Hide resolved
pennylane/gradients/classical_jacobian.py Outdated Show resolved Hide resolved
@JerryChen97
Copy link
Contributor

Also, the similar error handling branch in grad.py seems missing tests coverage.

Copy link
Contributor

@PietropaoloFrisoni PietropaoloFrisoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@albi3ro albi3ro merged commit 37abd58 into master Dec 31, 2024
46 checks passed
@albi3ro albi3ro deleted the math-grad branch December 31, 2024 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants